package com.xxk.rocket.star.core.context;

import com.xxk.rocket.star.core.dto.ConsumeMethodsDTO;
import com.xxk.rocket.star.core.dto.StargateThreadSizeDTO;
import com.xxk.rocket.star.core.exception.StargateException;
import org.apache.commons.beanutils.BeanUtils;

public class ConsumeContext extends StargateContext {

  @Override
  public ConsumeContext clone() throws CloneNotSupportedException {
    ConsumeContext consumeContext = new ConsumeContext();
    try {
      for (Class aClass : data.keySet()) {
        Object o = data.get(aClass);
        consumeContext.data.put(aClass, BeanUtils.cloneBean(o));
      }
    } catch (Exception e) {
      throw new StargateException("copy ConsumeContext error:", e);
    }
    return consumeContext;
  }

  @Override
  public boolean isValid() {
    ConsumeMethodsDTO producerMethodsDTO = (ConsumeMethodsDTO) data
            .get(ConsumeMethodsDTO.class);
    return producerMethodsDTO.isValid();
  }

  public int getThreadSize() {
    StargateThreadSizeDTO threadSizeDTO = (StargateThreadSizeDTO) data
            .get(StargateThreadSizeDTO.class);
    return threadSizeDTO.getThreadSize();
  }
}
